 

import java.util.ArrayList;

/**
 * Associate Controller
 * @author Stefan
 */
public class AssociateContainer
{
    //Attributes
    private ArrayList<Associate> assocs;
    private static AssociateContainer instance = new AssociateContainer();

    private AssociateContainer()
    {
        assocs = new ArrayList<Associate>();
    }

    /**
     * Singleton
     * @return Instance of AssociateContainer
     */
    public static AssociateContainer getInstance()
    {
        return instance;
    }

    public boolean addAssociate(Associate ass)
    {
        assocs.add(ass);
        return true;
    }

    public void clearAssociates()
    {
        assocs.clear();
    }

    public int getSize()
    {
        return assocs.size();
    }

    /**
     * Removes an Associate from the AssociateContainer
     * @param ass
     */
    public void deleteAssociate(Associate ass)
    {
        assocs.remove(ass);
    }

    /**
     * Find Associate by id
     * @param id
     * @return Associate
     */
    public Associate findAssociateID(String id)
    {
        Associate found = null;
        for (Associate ass : assocs)
        {
            if (ass.getId().equals(id))
            {
                found = ass;
            }
        }
        return found;
    }

    /**
     * finds an Customer from the Customer name. Return null if not found
     * @param name
     * @return Customer or null (if not found)
     */
    public Customer findCustomerName(String name)
    {
        Customer found = null;
        for (Associate ass : assocs)
        {
            if (ass instanceof Customer)
            {
                if (ass.getName().equals(name))
                {
                    found = (Customer) ass;
                }
            }
        }
        return found;
    }

    /**
     * Find supplier by name
     * @param name
     * @return Supplier
     */
    public Supplier findSupplierName(String name)
    {
        Supplier found = null;
        for (Associate ass : assocs)
        {
            if (ass instanceof Supplier)
            {
                if (ass.getName().equals(name))
                {
                    found = (Supplier) ass;
                }
            }
        }
        return found;
    }

    /**
     * finds an Employee from the ID. Return null if not found
     * @param ID
     * @return Emplyee or null (if not found)
     */
    public Employee findEmployeeID(String ID)
    {
        Employee found = null;
        for (Associate ass : assocs)
        {
            if (ass instanceof Employee)
            {
                if (ass.getId().equals(ID))
                {
                    found = (Employee) ass;
                }
            }
        }
        return found;
    }

    /**
     * Find Customer by ID
     * @param ID
     * @return Customer
     */
    public Customer findCustomerID(String ID)
    {
        Customer found = null;
        for (Associate ass : assocs)
        {
            if (ass instanceof Customer)
            {
                if (ass.getId().equals(ID))
                {
                    found = (Customer) ass;
                }
            }
        }
        return found;
    }

    /**
     * Find Supplier by ID
     * @param ID
     * @return Supplier
     */
    public Supplier findSupplierID(String ID)
    {
        Supplier found = null;
        for (Associate ass : assocs)
        {
            if (ass instanceof Supplier)
            {
                if (ass.getId().equals(ID))
                {
                    found = (Supplier) ass;
                }
            }
        }
        return found;
    }
}
